package cn.iocoder.yudao.framework.web.core.util;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    public HttpServletRequest getRequest() {
        return WebFrameworkUtils.getRequest();
    }

    protected Long getLoginUserId() {
        return WebFrameworkUtils.getLoginUserId();
    }

    public String getRemoteIP() {
        HttpServletRequest request = getRequest();
        return ServletUtils.getRemoteIP(request);
    }


    public void putToSession(String key, Object value) {
        getRequest().getSession().setAttribute(key, value);
    }

    public <T> T getFromSession(String key) {
        return (T) getRequest().getSession().getAttribute(key);
    }

    public String getFromCookie(String key) {
        if (StringUtils.isBlank(key)) {
            return null;
        }
        return ServletUtils.getCookieValue(getRequest(), key);
    }

}
